//
//  TitleButton.swift
//  SwiftWB
//
//  Created by 钟清 on 17/3/26.
//  Copyright © 2017年 Zhong Qing. All rights reserved.
//

import UIKit

class TitleButton: UIButton {

    /// 代码的实现
    override init(frame: CGRect) {
        super.init(frame: frame)
        setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Normal)
        setImage(UIImage(named: "navigationbar_arrow_up"), forState: UIControlState.Selected)
        setTitleColor(UIColor.darkTextColor(), forState: UIControlState.Normal)
        sizeToFit()
    }
    
    /// xib/storyboard的实现
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = (titleLabel?.frame.width)!
    }
    override func setTitle(title: String?, forState state: UIControlState) {
        super.setTitle((title ?? "") + " ", forState: UIControlState.Normal)
    }
    

}
